/*
 * @Author: your name
 * @Date: 2021-03-07 08:08:49
 * @LastEditTime: 2021-07-22 17:00:24
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \vue3-antd-koa\vue3-antd-pc\src\use\http.js
 */
import axios from 'axios';
axios.interceptors.request.use(
    config => {
        config.baseURL = "/api"
        let token = localStorage.getItem('token');
        if (token) config.headers.authorization = `Bearer ${token}`;
        return config
    },
    err => Promise.reject(err)
)
const isDEV = process.env.NODE_ENV === 'production'
axios.interceptors.response.use(
    res => res.data,
    err => {
        if (isDEV) {
            console.log(err.response.data)
        }
        return Promise.reject(err.response.data)
    }
)

export const lazyRequest = (request, delay = 1000) => {
    const promise = new Promise(resolve => { setTimeout(resolve, delay) })
    return Promise.all([request, promise])
}

export default axios